package com.context;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * Created by IntelliJ IDEA.
 * User: zyl
 * Date: 2006-11-6
 * Time: 15:34:06
 * To change this template use File | Settings | File Templates.
 */
public class ServiceFactory  extends HttpServlet {
    private static WebApplicationContext wac = null;

    private final static String USERSERVICE = "userService";
    
    //for hibernate
//    private final static String HIBERNATEFJSERVICE = "hibernateFjService";
//    private static HibernateFjService hibernateFjService =null;

    public void init() throws ServletException {
        ServletContext servletContext = getServletContext();
        wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        //for hibernate
//        hibernateFjService = (HibernateFjService) wac.getBean(HIBERNATEFJSERVICE);

    }

	public static WebApplicationContext getWac() {
        return wac;
    }

    public static void setWac(WebApplicationContext wac) {
        ServiceFactory.wac = wac;
    }

    private Object getBean(String beanName) {
        return wac.getBean(beanName);
    }
}